let str: string = "defddfrt";

const uniq = (str: string) => {
  let arr = str.split("");
  let newArr: string[] = [];
  arr.forEach((item) => {
    if (newArr.indexOf(item) === -1) {
      newArr.push(item);
    }
  });
  return newArr.join("");
};
console.log(uniq(str));
let but = document.querySelector("#but") as HTMLElement;
but.onclick = function () {
  let code: string = Math.random().toString(36).slice(-4);
  let color: string = "#" + Math.random().toString().slice(-6);
  console.log(color);
  let size: string = Math.floor(Math.random() * 31 + 12) + "px";
  but.innerHTML = code;
  but.style.color = color;
  but.style.fontSize = size;
};
const more = (arr: number[]) => {
  let obj: { [key: number | string]: number } = {};
  for (let i = 0; i < arr.length; i++) {
    if (!obj[arr[i]]) {
      obj[arr[i]] = 1;
    } else {
      obj[arr[i]]++;
    }
  }
  let key = Object.keys(obj);
  let max = "",
    maxNum = 0;
  for (let i = 0; i < key.length; i++) {
    if (obj[key[i]] > maxNum) {
      maxNum = obj[key[i]];
      max = key[i];
    }
  }
  console.log(maxNum);
  return max;
};
console.log(more([1, 5, 1, 8]));

const unite = (a: number[], b: number[]) => {
  let arr = new Set([...a, ...b]);
  return arr;
};
console.log(unite([1, 3, 2], [5, 2, 1, 4]));

const findLongerWord = (word: string) => {
  let arr = word.split(" ");
  let max = arr[0]
  for (let i = 0; i < arr.length; i++) {
    if (arr[i].length > max.length) {
      max = arr[i]
    }
  }

  return max;
};
console.log(findLongerWord("The quick brown fox jumped over the lazy dog"));

function maxValue<T>(can:T[]):T[]{
  let max = can[0]
  let arr: T[] = []
 for (let i:number = 0; i < can.length; i++) {
   if(can[i]>max){
     max=can[i]
     
   }
 }
 
  return arr
}
console.log(maxValue<number>([1,9,5,3,4,1]));

